﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace ComputerResourceConsole.common
{
    public class CommonMethod
    {
        public delegate void CommonEvent(object sender, EventArgs e);

        /// <summary>
        /// 程序所在路径
        /// </summary>
        /// <returns></returns>
        public static string getAppDirection()
        {
            return System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
        }

        public static bool createFile(String fileName)
        {
            try
            {
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                    Stream s = File.Create(fileName);
                    s.Close();
                    return true;
                }
                else
                {
                    FileInfo file = new FileInfo(fileName);
                    DirectoryInfo direct_info = file.Directory;
                    string directory = direct_info.FullName;
                    if (!Directory.Exists(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }
                    Stream s = File.Create(fileName);
                    s.Close();
                    return true;
                }
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}
